<?php
session_start();

// Parametros de configuracion
include_once('configuracion.php');

// Funciones de acceso a BD
include_once('interface_db.php');

//if (isset($_SESSION['paramdb']) && isset($_SESSION['USUARIO'])){
if (isset($_SESSION['paramdb'])){

?>
		<div class="portlet-header fixed">
        	<img src="images/icons/feed.gif" width="16" height="16" alt="" /> Lista de Paises
        </div>
		<div class="portlet-content nopadding">
        <form action="" method="post">
          <table width="100%" cellpadding="0" cellspacing="0" id="box-table-a" summary="">
            <thead>	
              <tr>
                <th width="20" scope="col"></th>
                <th width="60%" scope="col">Pais</th>
                <th width="10%" scope="col">Codigo</th>
                <th width="10%" scope="col">Estatus</th>
                <th width="10%" scope="col">Editar</th>
				<th width="10%" scope="col">Eliminar</th>
              </tr>
            </thead>
            <tbody>
			<?php
				$objdb = new DBSql($_SESSION['paramdb']);
				$objdb -> db_connect();
				if ($objdb -> is_connection()){
					$rsPaises = $objdb -> sqlListaPaises();
			
					if (mysql_num_rows($rsPaises)!=0){
			
						while ($row = mysql_fetch_array($rsPaises)){
						
							$idPais = $row["idPais"];
							$descripcion = $row["Descripcion"];
							$codigo = $row["Codigo"];
							$estatus = $row["Estatus"];
							$estado = "INACTIVO";
							
							if($estatus==1){
								$estado = 'ACTIVO';
							}
			?>
							<tr>
								<td width="20"></td>
								<td><?= $descripcion; ?></td>
								<td><?= $codigo; ?></td>
								<td><?= $estado; ?></td>
								<td><a href="#" onClick="Operacion_Pais('1','<?=$idPais ?>','<?=$descripcion ?>')" class="edit_icon" title="Editar"></a></td>
								<td><a href="#" onClick="Operacion_Pais('2','<?=$idPais ?>','<?=$descripcion ?>')" class="delete_icon" title="Eliminar"></a></td>
							</tr>
			 <?php
						}
						mysql_free_result($rsPaises);
					}
				}
			 
			 ?>
			 
              <tr class="footer">
                <td colspan="5">								
					<a href="#" class="button_grey_round" onClick="Operacion_Pais('0','agregar')"><span>Agregar</span></a>
				</td>
                <td align="right">&nbsp;</td>
			  </tr>
            </tbody>
          </table>
        </form>
		</div>
		
<?php		

}else{
	header("Location: error.php");
  	exit();
}

?>	

<script type="text/javascript">

	function Operacion_Pais(accion, idPais, descripcion){	
		/*
			accion = 0  --> Nuevo
			accion = 1  --> Editar
			accion = 2  --> Eliminar
		*/

		if (accion == 2){
	
			jConfirm('Desea eliminar el pais: ' + descripcion + ' ?', 'Sistema de Control Academico', function(r) {
							
				if(r){
						
					$("#content_portlet").html("<center><img src='images/ajax-loader.gif'><br><b>Actualizando informacion</b>"+
																	"<br>Por favor espere...</center>");
					$("#content_portlet").load("deletePais.php?p="+Math.random(), { idPais: idPais });
						
					//jAlert('La elimino la seccion satisfactoriamente ', 'Confirmacion de Eliminar');
						
				}else{
					return false;
				}
							
			});
		
		}else{
		
			$("#content_portlet").html("<center><img src='images/ajax-loader.gif'><br><b>Actualizando informacion</b>"+
																"<br>Por favor espere...</center>");
			$("#content_portlet").load("formPais.php?p="+Math.random(), { idPais: idPais, accion: accion });
		
		}

	}
	
</script>	